﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace TechnicalAnalysisEngine.Tests
{
    [TestClass]
    public class TestMovingAverageEnvelopes
    {
        List<double> inputSignalSMA;
        List<double> inputSignalEMA;

        int smaPeriods;
        int emaPeriods;

        int expectedSMAResultCount;
        int expectedEMAResultCount;

        double percentage;

        [TestInitialize]
        public void Initialize()
        {
            inputSignalSMA = new List<double>()
            {
                22.27,22.19,22.08,22.17,22.18,22.13,22.23,22.43,22.24,22.29,22.15,22.39,22.38,22.61,23.36,24.05,23.75,23.83,
                23.95,23.63,23.82,23.87,23.65,23.19,23.10,23.33,22.68,23.10,22.40,22.17
            };

            inputSignalEMA = new List<double>()
            {
                22.27, 22.19, 22.08, 22.17, 22.18, 22.13, 22.23, 22.43, 22.24, 22.29, 22.15, 22.39, 22.38, 22.61, 22.36, 
                24.05, 23.75, 23.83, 23.95, 23.63, 23.82, 23.87, 23.65, 23.19, 23.10, 23.33, 22.68, 23.10, 22.40, 22.17
            };

            smaPeriods = 10;
            emaPeriods = 10;

            expectedSMAResultCount = 21;
            expectedEMAResultCount = 21;

            percentage = 2.5;
        }

        [TestMethod]
        public void TestMovingAverageEnvelopesSMAValues()
        {
            var result = AnalysisEngine.MovingAverageEnvelopes(inputSignalSMA, Entities.MovingAverageType.Simple, smaPeriods, percentage);

            Assert.AreEqual(expectedSMAResultCount, result.LowerEnvelope.Count);
            Assert.AreEqual(expectedSMAResultCount, result.MovingAverage.Count);
            Assert.AreEqual(expectedSMAResultCount, result.UpperEnvelope.Count);
        }

        [TestMethod]
        public void TestMovingAverageEnvelopesEMAValues()
        {
            var result = AnalysisEngine.MovingAverageEnvelopes(inputSignalEMA, Entities.MovingAverageType.Exponential, emaPeriods, percentage);

            Assert.AreEqual(expectedEMAResultCount, result.LowerEnvelope.Count);
            Assert.AreEqual(expectedEMAResultCount, result.MovingAverage.Count);
            Assert.AreEqual(expectedEMAResultCount, result.UpperEnvelope.Count);
        }
    }
}
